<?php


namespace app\common\controller;

use app\common\model\Merchant;
use app\common\model\Paylog;
use think\Controller;
use Ylb\Ylb;

class Deviceobj extends Controller
{
    public function ylb_sendvoice($orderid){
        $Paylog=new Paylog();
        $payinfo=$Paylog->where(['orderid'=>$orderid])->find();
        if($payinfo['pay_fs']==4){
            return false;
        }
        $Merchant=new Merchant();
        $minfo=$Merchant
            ->alias('a')
            ->join('wn_agent b','a.agent=b.id','left')
            ->where(['a.id'=>$payinfo['mid']])->field('a.ylb_deviceid as ylb_deviceid,b.ylb_app_cust_id as ylb_app_cust_id,b.ylb_app_cust_pwd as ylb_app_cust_pwd')
            ->find();
        if($minfo['ylb_app_cust_id']=="" || $minfo['ylb_app_cust_pwd']=="" || $minfo['ylb_deviceid'] ==""){
            return false;
        }
        $option=[
            'app_cust_id'=>$minfo['ylb_app_cust_id'],
            'app_cust_pwd'=>$minfo['ylb_app_cust_pwd'],
        ];
        $Ylb=new Ylb($option);
        $deviceid=$minfo['ylb_deviceid'];
        $price=$payinfo['price']*100;
        switch ($payinfo['pay_fs']) {
            case 0:
                $re_param = 2;
                break;
            case 1:
                $re_param =1;
                break;
            case 2:
                $re_param = 2;
                break;
            case 3:
                $re_param = 1;
                break;
            case 5:
                $re_param = 7;
                break;
            case 8:
                $re_param = 8;
                break;
        }
        $info=$Ylb->addvoice($deviceid,$price,$re_param);
        return $info;
    }

}